<template>
  <div >
    <back />
    <nav>多人聊天</nav>
    <public-msg key="public" />
    <public-input />
  </div>
</template>
<script>
import Back from "../../../../components/Back/Back.vue";
import PublicInput from "./PublicInput.vue";
import PublicMsg from "./PublicMsg.vue";
export default {
  components: { Back, PublicMsg, PublicInput },
  name: "",
  data() {
    return {
      msgList: [],
      newMsg: {}
    };
  },
  created() {
    //初始化群聊天记录
    this.initMsgList();
  },
  computed: {
    //用户自己的id
    _id() {
      return (
        this.$store.getters.user._id ||
        JSON.parse(localStorage.getItem("userInfo"))._id || ''
      );
    },
    //用户信息
    userInfo() {
      return (
        this.$store.getters.user || JSON.parse(localStorage.getItem("userInfo")) ||''
      );
    }
  },
  methods: {
    initMsgList() {//初始化群聊天记录
      this.$axios({
        url: "/chat/getpublic"
      }).then(res => {
        // console.log(res.data)
        this.$store.dispatch("GetAllMsg", res.data);
      });
    }
  }
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
nav {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  background-color: aqua;
  text-align: center;
  height: 48px;
  line-height: 44px;
  z-index: 10;
}
</style>
